#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

class Solution {
private:
    unordered_map<char, int> symbolValues = {
        {'I', 1},
        {'V', 5},
        {'X', 10},
        {'L', 50},
        {'C', 100},
        {'D', 500},
        {'M', 1000}
    };
public:
    int romanToInt(string s)
    {
        int result = 0;
        int n = s.size();
        for (int i = 0; i < n; ++i) {
            int value = symbolValues[s[i]]; // 判断每个字符的数值
            // 不越界,且小字符在大字符左边
            if (i < n - 1 && value < symbolValues[s[i + 1]]) {
                result -= value;
            } else {
                result += value;
            }
        }
        return result;
    }
};

int main()
{
    cout << "Hello World!" << endl;
    return 0;
}
